package com.jielihaofeng.task;

import com.jielihaofeng.service.WeatherEmailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @description 天气预报信息邮件发送定时任务
 * @author Johnnie Wind
 * @date 2020/11/28 22:32
 */
@Component
public class WeatherEmailScheduleTask {

    // 日志记录
    private final Logger logger = LoggerFactory.getLogger(WeatherEmailScheduleTask.class);

    @Autowired
    private WeatherEmailService weatherEmailService;

//    @Scheduled(fixedRate = 10000)
    @Scheduled(cron = "0 0 7 * * ? ") // 每天7点执行
    private void configureTasks() {
        logger.info("天气预报邮件定时任务开始时间: " + LocalDateTime.now());
        weatherEmailService.sendEmail();
        logger.info("天气预报邮件定时任务结束时间: " + LocalDateTime.now());
    }

}
